package com.ctcc.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
@Service
public class ConfigUtils {
	private static final Logger logger = LoggerFactory.getLogger(ConfigUtils.class);
	private static Properties properties;


	private static Properties getInstance() {
		if (properties == null) {
			synchronized (ConfigUtils.class) {
				if (properties == null) {
					properties = new Properties();
					InputStream io = ConfigUtils.class.getResourceAsStream("/config.properties");
					try {
						properties.load(io);
					} catch (IOException e) {
						logger.error("IOException:",e);
					} finally {
						if(io!=null){
							try {
								io.close();
							} catch (IOException e) {
								logger.error("IOException:",e);
							}
						}
					}
				}
			}
		}
		return properties;
	}
	public static String getString(String key){
		return getInstance().getProperty(key);
	}
	public  static String getAppId(){
		return getInstance().getProperty(Const.appId);
	}
	public  static String getSecret(){
		return getInstance().getProperty(Const.secret);
	}
	public static void main(String[] args) {
		System.err.println(getString(Const.host));
	}
}
